﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Patterns
{
    public class ProductDao
    {
        public object GetProduct(ProductCriteria predicate)
        {
            return null;
        }
    }

    public abstract class ProductCriteria
    {
        internal ProductCriteria(Expression<Func<object, bool>> query)
        {
            this.Query = query;
        }

        public Expression<Func<object, bool>> Query { get; private set; }
    }

    public class ProductIdEqCriteria : ProductCriteria
    {
        public ProductIdEqCriteria(int id)
            : base(p => p == id.ToString())
        { }
    }

    public class QueryObjectPattern
    {

        public void Test()
        {
            ProductDao pd = new ProductDao();
            pd.GetProduct(new ProductIdEqCriteria(1));
        }
    }
}
